﻿@{
	Layout = "~/Views/Shared/_Layout.cshtml";
}

@using dPet.Application.DataObjects;

@model IEnumerable<dPet.Application.DataObjects.StaffRoleDto>

@helper GetPrivileges(PrivilegesDto privileges)
{ 
	var privilegeNames = new List<string>();

	foreach (PrivilegesDto item in Enum.GetValues(typeof(PrivilegesDto)))
	{
		if ((privileges & item) == item)
		{
			privilegeNames.Add(Hangerd.Utility.CommonTools.GetEnumDescription(item));
		}
	}

	@Html.Raw(string.Join("、", privilegeNames))
}

<div class="clearfix">
	<h4>角色管理</h4>

	<hr />

	<div class="panel panel-default clearfix">
		<div class="panel-heading">
			<a href="@Url.Action("StaffRole", "Manage")" class="btn btn-sm btn-success" target="_self"><span class="glyphicon glyphicon-plus-sign"></span> 添加角色</a>
		</div>

		<table class="table text-center table-striped table-hover">
			<thead>
				<tr>
					<th class="text-center" width="200px">角色名称</th>
					<th class="text-center">权限</th>
					<th class="text-center" width="150px">操作</th>
				</tr>
			</thead>
			<tbody>
				@foreach (var role in Model)
				{
					<tr>
						<td>@role.Name</td>
						<td>@GetPrivileges(role.Privileges)</td>
						<td>
							@Html.ActionLink("编辑", "StaffRole", new { id = role.Id })
						</td>
					</tr>
				}
			</tbody>
		</table>
	</div>
</div>

@section scripts {
	<script type="text/javascript">
	</script>
}
